<?php
class User
{
    public $users = array();
    public $adminData = array();
    function ListUsers()
    {
      require_once '../../Common/Model/DBConnection.php';
      $db_connect = new DB_Connection();
      $db_connect->connect();
      $query=  mysql_query("call sp_admin_all_data()");
      while($row = mysql_fetch_array($query))
      {
         $this->users[]= $row; 
      }
      $db_connect->disconnect();
    }
    
    function deleteUser($username)
    {
        require_once '../../Common/Model/DBConnection.php';
        $db_connect = new DB_Connection();
        $db_connect->connect();
        mysql_query("call sp_delete_admin_data('$username')");
        $db_connect->disconnect();
    }
    
    function editUser($username,$first_name,$father_name,$grandfather_name,$email)
    {
        require_once '../../Common/Model/DBConnection.php';
        $db_connect = new DB_Connection();
        $db_connect->connect();
        if (mysql_query("call sp_edit_admin_data('$username','$first_name','$father_name','$grandfather_name','$email')"))
        {
            $_SESSION['EditUser']=true;
        }
        else{
            $_SESSION['EditUser']=false;
        }
            $db_connect->disconnect();
        }
    
    function getAdminData($username)
    {
        require_once '../../Common/Model/DBConnection.php';
        $db_connect = new DB_Connection();
        $db_connect->connect();
        $query = mysql_query("call sp_get_admin_data('$username')");
        $row = mysql_fetch_array($query);
        $this->adminData[]= $row;
        $db_connect->disconnect();
    }
    
    function updatePassword($username)
    {
        require_once '../../Common/Model/DBConnection.php';
        $db_connect = new DB_Connection();
        $db_connect->connect();
        if (mysql_query("call sp_edit_admin_data('$username','$first_name','$father_name','$grandfather_name','$email')"))
        {
            $_SESSION['EditUser']=true;
        }
        else{
            $_SESSION['EditUser']=false;
        }
            $db_connect->disconnect();
    }
}
?>
